package com.ysw.test

import android.content.Context
import android.util.AttributeSet
import kotlin.jvm.JvmOverloads
import android.widget.TextView
import android.view.ViewConfiguration
import android.view.MotionEvent
import android.view.View
import androidx.core.view.ViewCompat

class DependencyView @JvmOverloads constructor(
    context: Context?,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
    private var mLastX = 0f
    private var mLastY = 0f

    override fun onTouchEvent(event: MotionEvent): Boolean {
        // return super.onTouchEvent(event);
        val action = event.action
        when (action) {
            MotionEvent.ACTION_DOWN -> {
                mLastX = event.x
                mLastY = event.y
            }
            MotionEvent.ACTION_MOVE -> {
                val deltax = (event.x - mLastX).toInt()
                val deltay = (event.y - mLastY).toInt()

                    ViewCompat.offsetTopAndBottom(this, deltay)
                    ViewCompat.offsetLeftAndRight(this, deltax)
                    mLastX = event.x
                    mLastY = event.y

            }
            MotionEvent.ACTION_UP -> {
                mLastX = event.x
                mLastY = event.y
            }
            else -> {}
        }
        return true
    }
}